using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinDataSource;
using Infragistics.Win.UltraWinGrid;
using PluginFrame;

namespace ExperimentRuleEditor
{
	public class Expression_Analysis : Form
	{
		private IContainer components;

		private UltraGrid ultraGridAnalysis;

		private Button btRemove;

		private Button btAdd;

		private Button btOk;

		private Button btCancel;

		protected IConfigurationService mConfigurationService;

		private readonly IPcrLogService mPcrLogService;

		private List<string> m_LListSelectExpression;

		private IApplication mApplication;

		private IRuleItem m_LRuleItem;

		private string m_LProjectName;

		private Dictionary<string, string[]> m_LExpressionAnalysis;

		protected ResourceManager mResourceManager;

		private string mExpressionKey = string.Empty;

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExperimentRuleEditor.Expression_Analysis));
			Infragistics.Win.Appearance appearance = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
			this.ultraGridAnalysis = new Infragistics.Win.UltraWinGrid.UltraGrid();
			this.btRemove = new System.Windows.Forms.Button();
			this.btAdd = new System.Windows.Forms.Button();
			this.btOk = new System.Windows.Forms.Button();
			this.btCancel = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)this.ultraGridAnalysis).BeginInit();
			base.SuspendLayout();
			this.ultraGridAnalysis.AccessibleDescription = null;
			this.ultraGridAnalysis.AccessibleName = null;
			resources.ApplyResources(this.ultraGridAnalysis, "ultraGridAnalysis");
			this.ultraGridAnalysis.BackgroundImage = null;
			appearance.BackColor = System.Drawing.SystemColors.Window;
			appearance.BorderColor = System.Drawing.Color.White;
			resources.ApplyResources(appearance, "appearance31");
			resources.ApplyResources(appearance.FontData, "appearance31.FontData");
			appearance.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Appearance = appearance;
			this.ultraGridAnalysis.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
			this.ultraGridAnalysis.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.False;
			appearance2.BackColor = System.Drawing.SystemColors.ActiveBorder;
			appearance2.BackColor2 = System.Drawing.SystemColors.ControlDark;
			appearance2.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
			appearance2.BorderColor = System.Drawing.SystemColors.Window;
			resources.ApplyResources(appearance2, "appearance32");
			resources.ApplyResources(appearance2.FontData, "appearance32.FontData");
			appearance2.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.GroupByBox.Appearance = appearance2;
			appearance3.ForeColor = System.Drawing.SystemColors.GrayText;
			resources.ApplyResources(appearance3, "appearance33");
			resources.ApplyResources(appearance3.FontData, "appearance33.FontData");
			appearance3.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.GroupByBox.BandLabelAppearance = appearance3;
			this.ultraGridAnalysis.DisplayLayout.GroupByBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
			appearance4.BackColor = System.Drawing.SystemColors.ControlLightLight;
			appearance4.BackColor2 = System.Drawing.SystemColors.Control;
			appearance4.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
			appearance4.ForeColor = System.Drawing.SystemColors.GrayText;
			resources.ApplyResources(appearance4, "appearance34");
			resources.ApplyResources(appearance4.FontData, "appearance34.FontData");
			appearance4.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.GroupByBox.PromptAppearance = appearance4;
			this.ultraGridAnalysis.DisplayLayout.MaxColScrollRegions = 1;
			this.ultraGridAnalysis.DisplayLayout.MaxRowScrollRegions = 1;
			appearance5.BackColor = System.Drawing.SystemColors.Window;
			appearance5.ForeColor = System.Drawing.SystemColors.ControlText;
			resources.ApplyResources(appearance5, "appearance35");
			resources.ApplyResources(appearance5.FontData, "appearance35.FontData");
			appearance5.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Override.ActiveCellAppearance = appearance5;
			this.ultraGridAnalysis.DisplayLayout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Dotted;
			this.ultraGridAnalysis.DisplayLayout.Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Dotted;
			appearance6.BorderColor = System.Drawing.Color.Silver;
			resources.ApplyResources(appearance6, "appearance36");
			appearance6.TextTrimming = Infragistics.Win.TextTrimming.EllipsisCharacter;
			resources.ApplyResources(appearance6.FontData, "appearance36.FontData");
			appearance6.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Override.CellAppearance = appearance6;
			this.ultraGridAnalysis.DisplayLayout.Override.CellPadding = 0;
			appearance7.BackColor = System.Drawing.SystemColors.Control;
			appearance7.BackColor2 = System.Drawing.SystemColors.ControlDark;
			appearance7.BackGradientAlignment = Infragistics.Win.GradientAlignment.Element;
			appearance7.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
			appearance7.BorderColor = System.Drawing.SystemColors.Window;
			resources.ApplyResources(appearance7, "appearance37");
			resources.ApplyResources(appearance7.FontData, "appearance37.FontData");
			appearance7.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Override.GroupByColumnAppearance = appearance7;
			resources.ApplyResources(appearance8, "appearance38");
			resources.ApplyResources(appearance8.FontData, "appearance38.FontData");
			appearance8.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Override.HeaderAppearance = appearance8;
			this.ultraGridAnalysis.DisplayLayout.Override.HeaderStyle = Infragistics.Win.HeaderStyle.WindowsXPCommand;
			appearance9.BackColor = System.Drawing.SystemColors.Window;
			appearance9.BorderColor = System.Drawing.Color.Silver;
			resources.ApplyResources(appearance9, "appearance39");
			resources.ApplyResources(appearance9.FontData, "appearance39.FontData");
			appearance9.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Override.RowAppearance = appearance9;
			appearance10.ImageAlpha = Infragistics.Win.Alpha.UseAlphaLevel;
			resources.ApplyResources(appearance10, "appearance41");
			resources.ApplyResources(appearance10.FontData, "appearance41.FontData");
			appearance10.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Override.RowSelectorAppearance = appearance10;
			this.ultraGridAnalysis.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.True;
			appearance11.BackColor = System.Drawing.SystemColors.ControlLight;
			resources.ApplyResources(appearance11, "appearance40");
			resources.ApplyResources(appearance11.FontData, "appearance40.FontData");
			appearance11.ForceApplyResources = "FontData|";
			this.ultraGridAnalysis.DisplayLayout.Override.TemplateAddRowAppearance = appearance11;
			this.ultraGridAnalysis.DisplayLayout.ScrollBounds = Infragistics.Win.UltraWinGrid.ScrollBounds.ScrollToFill;
			this.ultraGridAnalysis.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy;
			this.ultraGridAnalysis.Name = "ultraGridAnalysis";
			this.ultraGridAnalysis.DoubleClickHeader += new Infragistics.Win.UltraWinGrid.DoubleClickHeaderEventHandler(ultraGridAnalysis_DoubleClickHeader);
			this.ultraGridAnalysis.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(ultraGridAnalysis_InitializeLayout);
			this.ultraGridAnalysis.AfterSelectChange += new Infragistics.Win.UltraWinGrid.AfterSelectChangeEventHandler(ultraGridAnalysis_AfterSelectChange);
			this.btRemove.AccessibleDescription = null;
			this.btRemove.AccessibleName = null;
			resources.ApplyResources(this.btRemove, "btRemove");
			this.btRemove.BackgroundImage = null;
			this.btRemove.Font = null;
			this.btRemove.Name = "btRemove";
			this.btRemove.UseVisualStyleBackColor = true;
			this.btRemove.Click += new System.EventHandler(btRemove_Click);
			this.btAdd.AccessibleDescription = null;
			this.btAdd.AccessibleName = null;
			resources.ApplyResources(this.btAdd, "btAdd");
			this.btAdd.BackgroundImage = null;
			this.btAdd.Font = null;
			this.btAdd.Name = "btAdd";
			this.btAdd.UseVisualStyleBackColor = true;
			this.btAdd.Click += new System.EventHandler(btAdd_Click);
			this.btOk.AccessibleDescription = null;
			this.btOk.AccessibleName = null;
			resources.ApplyResources(this.btOk, "btOk");
			this.btOk.BackgroundImage = null;
			this.btOk.Font = null;
			this.btOk.Name = "btOk";
			this.btOk.UseVisualStyleBackColor = true;
			this.btOk.Click += new System.EventHandler(btOk_Click);
			this.btCancel.AccessibleDescription = null;
			this.btCancel.AccessibleName = null;
			resources.ApplyResources(this.btCancel, "btCancel");
			this.btCancel.BackgroundImage = null;
			this.btCancel.Font = null;
			this.btCancel.Name = "btCancel";
			this.btCancel.UseVisualStyleBackColor = true;
			this.btCancel.Click += new System.EventHandler(btCancel_Click);
			base.AccessibleDescription = null;
			base.AccessibleName = null;
			resources.ApplyResources(this, "$this");
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.BackgroundImage = null;
			base.Controls.Add(this.btOk);
			base.Controls.Add(this.btCancel);
			base.Controls.Add(this.btRemove);
			base.Controls.Add(this.btAdd);
			base.Controls.Add(this.ultraGridAnalysis);
			this.Font = null;
			base.Icon = null;
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "Expression_Analysis";
			base.ShowIcon = false;
			base.ShowInTaskbar = false;
			((System.ComponentModel.ISupportInitialize)this.ultraGridAnalysis).EndInit();
			base.ResumeLayout(false);
		}

		public Expression_Analysis(IApplication app, IRuleItem mRuleItem, string mProjectName, bool isLocked)
		{
			InitializeComponent();
			mApplication = app;
			mPcrLogService = (IPcrLogService)app.GetService("PcrLogService");
			mConfigurationService = (IConfigurationService)app.GetService("ConfigurationService");
			mResourceManager = ResourceManager.CreateFileBasedResourceManager("ExperimentRuleEditor", mApplication.GetResourceFolder() + GetType().Namespace + "\\", null);
			m_LRuleItem = mRuleItem;
			m_LProjectName = mProjectName;
			m_LExpressionAnalysis = mRuleItem.ExpressionAnalysis;
			InitializeForm();
		}

		private void InitializeForm()
		{
			try
			{
				UltraDataSource ultraDataSource = new UltraDataSource();
				ultraDataSource.Band.Columns.Add("Target");
				int num = 0;
				if (m_LExpressionAnalysis != null)
				{
					foreach (string key in m_LExpressionAnalysis.Keys)
					{
						if (key != "ColHeaderName")
						{
							string[] array = m_LExpressionAnalysis[key];
							if (array.Length > num)
							{
								num = array.Length;
							}
						}
					}
					for (int i = 0; i < num; i++)
					{
						mExpressionKey = "Expression " + (i + 1);
						ultraDataSource.Band.Columns.Add(mExpressionKey);
					}
				}
				else
				{
					mExpressionKey = "Expression " + 1;
					ultraDataSource.Band.Columns.Add(mExpressionKey);
				}
				object[] array2 = null;
				array2 = ((m_LExpressionAnalysis == null || num < 1) ? new object[2] : new object[num + 1]);
				if (m_LProjectName != null)
				{
					string[] array3 = m_LProjectName.Split(new string[1] { "," }, StringSplitOptions.None);
					if (array3 != null)
					{
						for (int j = 0; j < array3.Length; j++)
						{
							if (!(array3[j] != "N/A") || !(array3[j] != ""))
							{
								continue;
							}
							array2[0] = array3[j];
							if (m_LExpressionAnalysis != null)
							{
								if (m_LExpressionAnalysis.ContainsKey(array3[j]))
								{
									string[] array4 = m_LExpressionAnalysis[array3[j]];
									for (int k = 0; k < array4.Length; k++)
									{
										array2[k + 1] = array4[k];
									}
								}
								else
								{
									array2[1] = string.Empty;
								}
							}
							else
							{
								array2[1] = string.Empty;
							}
							ultraDataSource.Rows.Add(array2);
						}
					}
					else
					{
						array2[0] = string.Empty;
						array2[1] = string.Empty;
					}
				}
				else
				{
					array2[0] = string.Empty;
					array2[1] = string.Empty;
				}
				ultraGridAnalysis.DataSource = ultraDataSource;
				ultraGridAnalysis.DataBind();
				ultraGridAnalysis.DisplayLayout.Bands[0].Columns["Target"].Header.Caption = mResourceManager.GetString("TargetString");
				if (num == 0)
				{
					ultraGridAnalysis.DisplayLayout.Bands[0].Columns[1].Header.Caption = mResourceManager.GetString("RuleCalculationString") + " " + 1;
				}
				else
				{
					for (int l = 0; l < num; l++)
					{
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[l + 1].Header.Caption = m_LExpressionAnalysis["ColHeaderName"][l];
					}
				}
				foreach (UltraGridColumn column in ultraGridAnalysis.DisplayLayout.Bands[0].Columns)
				{
					if (!column.Header.Column.Key.Contains("Expression"))
					{
						continue;
					}
					ValueList valueList = new ValueList();
					int num2 = 1;
					foreach (IExressionEditor expressionEditor in m_LRuleItem.ExpressionEditorList)
					{
						if (expressionEditor.Expression_Display)
						{
							valueList.ValueListItems.Add(num2, expressionEditor.Expression_Name);
							num2++;
						}
					}
					valueList.ValueListItems.Add(num2, " ");
					column.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
					column.ValueList = valueList;
				}
				foreach (UltraGridColumn column2 in ultraGridAnalysis.DisplayLayout.Bands[0].Columns)
				{
					column2.PerformAutoResize(PerformAutoSizeType.AllRowsInBand);
					column2.Width += 24;
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void ultraGridAnalysis_InitializeLayout(object sender, InitializeLayoutEventArgs e)
		{
			try
			{
				e.Layout.Override.CellClickAction = CellClickAction.EditAndSelectText;
				e.Layout.Override.CellAppearance.BackColor = Color.White;
				e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.None;
				e.Layout.Override.RowSizing = RowSizing.AutoFixed;
				e.Layout.ViewStyleBand = ViewStyleBand.Horizontal;
				e.Layout.Override.RowSelectors = DefaultableBoolean.True;
				e.Layout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.SeparateElement;
				e.Layout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex;
				e.Layout.Override.RowSelectorStyle = HeaderStyle.Standard;
				e.Layout.Override.RowSelectorAppearance.TextHAlign = HAlign.Center;
				e.Layout.Override.RowSelectorAppearance.TextVAlign = VAlign.Middle;
				e.Layout.Override.RowSelectorAppearance.ImageAlpha = Alpha.Transparent;
				e.Layout.Override.ExpansionIndicator = ShowExpansionIndicator.Never;
				e.Layout.CaptionVisible = DefaultableBoolean.False;
				e.Layout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand;
				e.Layout.Override.AllowColMoving = AllowColMoving.NotAllowed;
				e.Layout.Override.AllowColSizing = AllowColSizing.None;
				e.Layout.Scrollbars = Scrollbars.Both;
				e.Layout.ScrollStyle = ScrollStyle.Immediate;
				e.Layout.Override.RowSizing = RowSizing.AutoFixed;
				e.Layout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand;
				e.Layout.Override.FilterClearButtonLocation = FilterClearButtonLocation.Row;
				e.Layout.Override.FilterOperandStyle = FilterOperandStyle.DropDownList;
				e.Layout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.Equals;
				e.Layout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.Equals;
				e.Layout.Override.FilterOperatorLocation = FilterOperatorLocation.Hidden;
				e.Layout.Override.RowFilterMode = RowFilterMode.SiblingRowsOnly;
				e.Layout.Override.SequenceFilterRow = 0;
				e.Layout.Override.SelectTypeCell = SelectType.Extended;
				e.Layout.Override.SelectTypeCol = SelectType.Extended;
				e.Layout.Override.SelectTypeRow = SelectType.Extended;
				e.Layout.UseFixedHeaders = true;
				e.Layout.Override.FixedHeaderIndicator = FixedHeaderIndicator.None;
				e.Layout.Bands[0].Columns["Target"].CellActivation = Activation.NoEdit;
				foreach (UltraGridColumn column in e.Layout.Bands[0].Columns)
				{
					column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand);
					column.Width += 4;
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void btAdd_Click(object sender, EventArgs e)
		{
			try
			{
				ultraGridAnalysis.Selected.Columns.Clear();
				bool flag = false;
				for (int i = 0; i < ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count; i++)
				{
					if (ultraGridAnalysis.DisplayLayout.Bands[0].Columns[i].Key.Contains("Expression") && ultraGridAnalysis.DisplayLayout.Bands[0].Columns[i].Hidden)
					{
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[i].Hidden = false;
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					if (ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count == 11)
					{
						MessageBox.Show(mResourceManager.GetString("ReachMaxExpressionColumString"), mResourceManager.GetString("HintString"));
						btAdd.Enabled = false;
						return;
					}
					if (ultraGridAnalysis.DisplayLayout.Bands[0].Columns[ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count - 1].Key.Contains("Expression"))
					{
						mExpressionKey = ultraGridAnalysis.DisplayLayout.Bands[0].Columns[ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count - 1].Key;
						string s = mExpressionKey.Replace("Expression", "");
						int result = 0;
						int num = 0;
						num = ((!int.TryParse(s, out result)) ? ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count : (int.Parse(s) + 1));
						mExpressionKey = "Expression " + num;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Insert(ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count, mExpressionKey);
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Header.Caption = mResourceManager.GetString("RuleCalculationString") + " " + num;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Header.Appearance.TextHAlign = HAlign.Center;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Header.VisiblePosition = ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count - 1;
						ValueList valueList = new ValueList();
						int num2 = 1;
						foreach (IExressionEditor expressionEditor in m_LRuleItem.ExpressionEditorList)
						{
							if (expressionEditor.Expression_Display)
							{
								valueList.ValueListItems.Add(num2, expressionEditor.Expression_Name);
								num2++;
							}
						}
						valueList.ValueListItems.Add(num2, " ");
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].ValueList = valueList;
					}
					else
					{
						string s2 = mExpressionKey.Replace("Expression", "");
						int result2 = 0;
						int num3 = 0;
						num3 = ((!int.TryParse(s2, out result2)) ? ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count : (int.Parse(s2) + 1));
						mExpressionKey = "Expression " + num3;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Insert(ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count, mExpressionKey);
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Header.Caption = mResourceManager.GetString("RuleCalculationString") + " " + num3;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Header.Appearance.TextHAlign = HAlign.Center;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Header.VisiblePosition = ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count - 1;
						ValueList valueList2 = new ValueList();
						int num4 = 1;
						foreach (IExressionEditor expressionEditor2 in m_LRuleItem.ExpressionEditorList)
						{
							if (expressionEditor2.Expression_Display)
							{
								valueList2.ValueListItems.Add(num4, expressionEditor2.Expression_Name);
								num4++;
							}
						}
						valueList2.ValueListItems.Add(num4, " ");
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[mExpressionKey].ValueList = valueList2;
					}
				}
				foreach (UltraGridColumn column in ultraGridAnalysis.DisplayLayout.Bands[0].Columns)
				{
					column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand);
					column.Width += 24;
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void btRemove_Click(object sender, EventArgs e)
		{
			try
			{
				for (int i = 0; i < m_LListSelectExpression.Count; i++)
				{
					for (int j = 0; j < ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count; j++)
					{
						if (!(ultraGridAnalysis.DisplayLayout.Bands[0].Columns[j].Key == m_LListSelectExpression[i]))
						{
							continue;
						}
						ultraGridAnalysis.DisplayLayout.Bands[0].Columns[j].Hidden = true;
						foreach (UltraGridRow row in ultraGridAnalysis.Rows)
						{
							row.Cells[j].Value = null;
						}
					}
				}
				btAdd.Enabled = true;
				btRemove.Enabled = false;
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void btOk_Click(object sender, EventArgs e)
		{
			try
			{
				if (ExpressionJudge())
				{
					SaveRuleGrid(ultraGridAnalysis, m_LRuleItem);
					base.DialogResult = DialogResult.OK;
					Close();
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		public bool SaveRuleGrid(UltraGrid grdExpression, IRuleItem mRuleItem)
		{
			Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>();
			int num = 0;
			for (int i = 1; i < grdExpression.DisplayLayout.Bands[0].Columns.Count; i++)
			{
				if (!grdExpression.DisplayLayout.Bands[0].Columns[i].Hidden)
				{
					num++;
				}
			}
			foreach (UltraGridRow row in grdExpression.Rows)
			{
				string[] array = new string[num];
				int num2 = 0;
				for (int j = 1; j < row.Cells.Count; j++)
				{
					if (!row.Cells[j].Column.Hidden)
					{
						if (num2 > num)
						{
							return false;
						}
						array[num2] = row.Cells[j].Text;
						num2++;
					}
				}
				dictionary.Add(row.Cells[0].Text, array);
			}
			string[] array2 = new string[num];
			int num3 = 0;
			foreach (UltraGridColumn column in grdExpression.DisplayLayout.Bands[0].Columns)
			{
				if (column.Key != "Target" && !column.Hidden)
				{
					if (num3 > num)
					{
						return false;
					}
					array2[num3] = column.Header.Caption;
					num3++;
				}
			}
			dictionary.Add("ColHeaderName", array2);
			mRuleItem.ExpressionAnalysis = dictionary;
			return true;
		}

		private void ultraGridAnalysis_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
		{
			try
			{
				if (typeof(Infragistics.Win.UltraWinGrid.ColumnHeader) != e.Type)
				{
					return;
				}
				m_LListSelectExpression = new List<string>();
				for (int i = 0; i < ultraGridAnalysis.Selected.Columns.Count; i++)
				{
					for (int j = 0; j < ultraGridAnalysis.DisplayLayout.Bands[0].Columns.Count; j++)
					{
						if (ultraGridAnalysis.DisplayLayout.Bands[0].Columns[j].Key == ultraGridAnalysis.Selected.Columns[i].Column.Key && ultraGridAnalysis.DisplayLayout.Bands[0].Columns[j].Key.Contains("Expression"))
						{
							btRemove.Enabled = true;
							m_LListSelectExpression.Add(ultraGridAnalysis.Selected.Columns[i].Column.Key);
						}
					}
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private bool ExpressionJudge()
		{
			try
			{
				for (int i = 0; i < ultraGridAnalysis.Rows.Count; i++)
				{
					int count = ultraGridAnalysis.Rows[i].Cells.Count;
					if (count <= 4)
					{
						continue;
					}
					for (int j = 1; j < count; j++)
					{
						if (ultraGridAnalysis.Rows[i].Cells[count - j].Text != "" && ultraGridAnalysis.Rows[i].Cells[count - j - 1].Text == "" && ultraGridAnalysis.Rows[i].Cells[count - j - 2].Text != "")
						{
							MessageBox.Show(mResourceManager.GetString("ExpressionColumnEmptyString"), mResourceManager.GetString("ErrorString"));
							return false;
						}
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
				return false;
			}
		}

		private void btCancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void ultraGridAnalysis_DoubleClickHeader(object sender, DoubleClickHeaderEventArgs e)
		{
			if (e.Header.Column.Key != "Target")
			{
				Expression_ColHeader expression_ColHeader = new Expression_ColHeader(e.Header.Caption);
				if (expression_ColHeader.ShowDialog() == DialogResult.OK)
				{
					e.Header.Caption = expression_ColHeader.ColHeaderName;
				}
			}
		}
	}
}
